home *** CD-ROM | disk | FTP | other *** search
- unit MonitorU;
-
- interface
-
- uses
- {$ifdef Ver90} //Delphi 2
- DB,
- {$else} //Delphi 3+
- DBTables,
- {$endif}
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, Buttons;
-
- type
- TSQLTraceForm = class(TForm)
- Label1: TLabel;
- Label2: TLabel;
- lstTrace: TListBox;
- memTrace: TMemo;
- TraceCategories: TGroupBox;
- CBPrepared: TCheckBox;
- CBExecuted: TCheckBox;
- CBInputParams: TCheckBox;
- CBFetchedData: TCheckBox;
- CBStatement: TCheckBox;
- CBConnect: TCheckBox;
- CBTransaction: TCheckBox;
- CBBlob: TCheckBox;
- CBMisc: TCheckBox;
- CBVendorErr: TCheckBox;
- CBVendor: TCheckBox;
- btnClear: TSpeedButton;
- chkAutoScroll: TCheckBox;
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure lstTraceClick(Sender: TObject);
- procedure btnClearClick(Sender: TObject);
- procedure CheckBoxClick(Sender: TObject);
- private
- FFileView: Pointer;
- FMemFile: THandle;
- FDLL: HModule;
- public
- function GetTraceOptions: Integer;
- procedure WndProc(var Msg: TMessage); override;
- end;
-
- var
- SQLTraceForm: TSQLTraceForm;
-
- implementation
-
- uses
- MonHelpU;
-
- {$R *.DFM}
-
- procedure TSQLTraceForm.FormCreate(Sender: TObject);
- begin
- //Give listbox a horizontal scroll bar
- SendMessage(lstTrace.Handle, lb_SetHorizontalExtent, 2000, 0);
- FDLL := LoadLibrary('MonLib.Dll');
- if FDLL <= 32 then
- ShowMessage('Cannot load support library');
- FMemFile := OpenFileMapping(FILE_MAP_READ, False, 'SMBuffer');
- if FMemFile = 0 then
- raise Exception.Create('Cannot open file mapping');
- FFileView := MapViewOfFile(FMemFile, FILE_MAP_READ, 0, 0, TraceBufSize);
- if FFileView = nil then
- raise Exception.Create('Cannot open file view');
- end;
-
- procedure TSQLTraceForm.FormDestroy(Sender: TObject);
- begin
- CloseHandle(FMemFile);
- if FDLL > 32 then
- FreeLibrary(FDLL)
- end;
-
- function TSQLTraceForm.GetTraceOptions: Integer;
- var
- Loop: Integer;
- begin
- Result := 0;
- for Loop := 0 to TraceCategories.ControlCount - 1 do
- if (TraceCategories.Controls[Loop] is TCheckBox) and
- TCheckBox(TraceCategories.Controls[Loop]).Checked then
- Inc(Result, TCheckBox(TraceCategories.Controls[Loop]).Tag);
- end;
-
- procedure TSQLTraceForm.WndProc(var Msg: TMessage);
- begin
- inherited;
- if Msg.Msg = wm_TraceMessage then
- begin
- Msg.Result := 1;
- lstTrace.Items.Add(StrPas(PChar(FFileView)));
- if chkAutoScroll.Checked then
- lstTrace.ItemIndex := lstTrace.Items.Count - 1
- end
- else
- if Msg.Msg = wm_ClientLibNotify then
- SendMessage(TWMClientLibNotify(Msg).Wnd, wm_MonitorNotify, Handle, GetTraceOptions);
- end;
-
- procedure TSQLTraceForm.lstTraceClick(Sender: TObject);
- begin
- memTrace.Text := lstTrace.Items[lstTrace.ItemIndex]
- end;
-
- procedure TSQLTraceForm.btnClearClick(Sender: TObject);
- begin
- lstTrace.Clear
- end;
-
- procedure TSQLTraceForm.CheckBoxClick(Sender: TObject);
- begin
- //Notify clients of new trace flags
- SendMessage(HWnd_Broadcast, wm_UpdateClients, GetTraceOptions, 0)
- end;
-
- end.
-